package interview.dp;

import java.util.Scanner;

/**
 * 2023.08.06-小红书-第二题-塔子哥的快乐值 https://codefun2000.com/p/P1430
 * 题目简述：有n件事每件消耗一定时间和精力获得一定快乐值，求有T时间和H精力最大可获得的快乐值
 */
public class HappyValue {

    /**
     * 思路：01背包-最大价值问题。只不过背包有两种类型容量限制，多套一层循环即可
     * 1. 定义dp：dp[i][t][h]为背包容量为t和h时，从前i个事件中选能获得的最大价值
     * 2. 状态转移公式：(1)若当前背包容量不能满足事件i，则dp[i][t][h] = dp[i-1][t][h];
     *               (2)若能满足，则dp[i][t][h] = max(dp[i-1][t][h], dp[i-1][t-events[i][0]][h-events[i][1]] + events[i][2]);
     * 3. 初始化：dp[0][t][h]=0；dp[i][0][h]=0；dp[i][t][0]=0；
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int T = sc.nextInt();
        int H = sc.nextInt();
        int[][] events = new int[n+1][3];
        for (int i = 1;i <= n;i++) {
            events[i][0] = sc.nextInt();//时间
            events[i][1] = sc.nextInt();//精力
            events[i][2] = sc.nextInt();//快乐值
        }
        long[][][] dp = new long[n+1][T+1][H+1];
        for (int i = 1;i <= n;i++) {
            for (int t = 1;t <= T;t++) {
                for (int h = 1;h <= H;h++) {
                    if (events[i][0] > t || events[i][1] > h) //判断当前容量是否能满足事件
                        dp[i][t][h] = dp[i-1][t][h];
                    else dp[i][t][h] = Math.max(dp[i-1][t][h], dp[i-1][t-events[i][0]][h-events[i][1]] + events[i][2]);
                }
            }
        }
        System.out.println(dp[n][T][H]);
    }
}
